package com.yisu.expressway.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yisu.expressway.R;

import com.yisu.expressway.model.ServiceDistrictObj;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/5 0005.
 */

public class GasListAdapter extends  RecyclerView.Adapter<GasListAdapter.GasViewHolder>  {

    ArrayList<ServiceDistrictObj.GasInfoObj> mData = new ArrayList<>();
    private Context mContext;

    public GasListAdapter (Context context){
        this.mContext = context;
    }

    public void setData(ArrayList<ServiceDistrictObj.GasInfoObj> list){
        this.mData = list;
        notifyDataSetChanged();
    }


    @Override
    public GasViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View mView = LayoutInflater.from(mContext).inflate(R.layout.gas_status_item, parent, false);
        return new GasViewHolder(mView);
    }

    @Override
    public void onBindViewHolder(GasViewHolder holder, int position) {
        if(mData.size() <= position ){
            return;
        }

        ServiceDistrictObj.GasInfoObj item = mData.get(position);
        holder.mTv_gas_name.setText(item.gasName);
        holder.mTv_gas_num.setText(item.gasNumber);
        holder.mTv_gas_status.setText(String.valueOf(item.gasStatus));

    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class GasViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.tv_gas_name) TextView mTv_gas_name;
        @Bind(R.id.tv_gas_number) TextView mTv_gas_num;
        @Bind(R.id.tv_gas_status) TextView mTv_gas_status;

        public GasViewHolder(View itemView){
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

}
